package com.triones.api.controller.api;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.triones.api.entity.vo.CountryDictVO;
import com.triones.api.entity.vo.StateDictVO;
import com.triones.api.service.CountryDictService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * api - 国家字典
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/countryDict")
public class ApiCountryDictController extends BaseController {

    private final CountryDictService countryDictService;

    /**
     * 获取国家字典列表
     */
    @SaIgnore
    @GetMapping("/listTree")
    public R<List<CountryDictVO>> list() {
        return R.ok(countryDictService.listTree());
    }

    /**
     * 用国家二字码获取部分国家州/省二字码
     */
    @SaIgnore
    @GetMapping("/stateListByCode")
    public R<List<StateDictVO>> stateListByCountryCode(@NotBlank(message = "国家代码不能为空") String countryCode,String keyword) {
        return R.ok(countryDictService.stateListByCountryCode(countryCode,keyword));
    }

    /**
     * 用国家id获取部分国家州/省二字码
     */
    @SaIgnore
    @GetMapping("/stateListById")
    public R<List<StateDictVO>> stateListByCountryId(@NotNull(message = "id不能为空") Long id,String keyword) {
        return R.ok(countryDictService.stateListByCountryId(id,keyword));
    }
}
